﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Coldairarrow.Entity.BTB_StaffUsers;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.Statistics;
using Coldairarrow.IBusiness.BTB_StaffUsers;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Coldairarrow.Api.Controllers.BTB_StaffUsers
{
    [Route("/BTB_StaffUsers/[controller]/[action]")]
    public class BTB_UserVisitController : BaseApiController
    {
        public BTB_UserVisitController(IBTB_UserVisitBusiness bTB_UserVisitBus)
        {
            _TB_UserVisitBus = bTB_UserVisitBus;
        }
        IBTB_UserVisitBusiness _TB_UserVisitBus { get; }

        #region 统计
        [NoCheckJWT]
        public async Task AddDataAsync(BTB_UserVisit data)
        {
            await _TB_UserVisitBus.AddDataAsync(data);
        }
        /// <summary>
        /// 用户统计
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public UserDTO IP()
        {
            return _TB_UserVisitBus.IP();
        }

        public int Getnotification()
        {
            return _TB_UserVisitBus.Getnotification();
        }
        /// <summary>
        /// 访客统计
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public VisitorDTO UV()
        {
            return _TB_UserVisitBus.UV();
        }
        /// <summary>
        /// 销量统计
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public SalesDTO Sales()
        {
            return _TB_UserVisitBus.Sales();
        }
        /// <summary>
        /// 销售额统计
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public SalesVolumeDTO SalesVolume()
        {
            return _TB_UserVisitBus.SalesVolume();
        }
        /// <summary>
        /// 订单量统计
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ClinchOrderDTO GetOrder()
        {
            return _TB_UserVisitBus.GetOrder();
        }
        /// <summary>
        /// 代办事项
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public TodoDTO GetTodo()
        {
            return _TB_UserVisitBus.GetTodo();
        }
        #endregion
        /// <summary>
        /// 插入ip
        /// </summary>
        /// <returns></returns>
        [NoCheckJWT]
        public async Task GetIP()
        {
            await _TB_UserVisitBus.GetIP();
        }

        /// <summary>
        /// 支付方式对应支付金额
        /// </summary>
        /// <returns></returns>
        [NoCheckJWT]
        [HttpPost]
        public async Task<PayDTO> GetPayStatse(PayStatseDTO input)
        {
           return await _TB_UserVisitBus.GetPayStatse(input);
        }

        #region 销量折线图
        /// <summary>
        /// 销量折线图
        /// </summary>
        /// <returns></returns>
        [NoCheckJWT]
        [HttpPost]
        public RetuenData GetLineChartGoodsNumber()
        {
            RetuenData data = new RetuenData();

            var Year = DateTime.Now.Year;
            List<LinChartStatistical> ModelList = _TB_UserVisitBus.GetDayGoodsNumber(Year);
            List<object> DataNameList = new List<object>();
            List<object> DataAmountList = new List<object>();
            if (ModelList != null)
            {
                foreach (var item in ModelList)
                {
                    DataNameList.Add(item.DTName);
                    DataAmountList.Add(item.Account);
                }
            }

            data.DataNameList = DataNameList;
            data.DataAmountList = DataAmountList;
            return data;
        }
        #endregion

        #region 销售额柱状图数据
        /// <summary>
        /// 销售额柱状图数据
        /// </summary>
        /// <returns></returns>
        [NoCheckJWT]
        [HttpPost]
        public RetuenData GetLineChartOrderPrice()
        {
            RetuenData data = new RetuenData();

            int Year = DateTime.Now.Year;
            List<LinChartStatistical> ModelList = _TB_UserVisitBus.GetDayOrderPrince(Year);
            List<object> DataNameList = new List<object>();
            List<object> DataAmountList = new List<object>();
            if (ModelList != null)
            {
                foreach (var item in ModelList)
                {
                    DataNameList.Add(item.DTName);
                    DataAmountList.Add(item.Amount);
                }
            }
            data.DataNameList = DataNameList;
            data.DataAmountList = DataAmountList;
            return data;
        }
        #endregion
        #region 前端UV

        #endregion
    }
    public class RetuenData
    {
        public List<object> DataNameList { get; set; }
        public List<object> DataAmountList { get; set; }
    }
}
